package com.projx.accounting.module;

import jakarta.persistence.*;

import java.time.OffsetDateTime;
import java.util.Objects;
import java.util.UUID;

@Entity
@Table(name = "bills")
public class Bill {
    @Id
    @Column(length = 36)
    private String id;

    private Double amount;

    private OffsetDateTime createdAt;

    @Column(name = "owner_id")
    private String ownerId;

    private String type;

    private String description;

    @PrePersist
    public void prePersist() {
        if (this.id == null) this.id = UUID.randomUUID().toString();
        if (this.createdAt == null) this.createdAt = OffsetDateTime.now();
    }

    public Bill() {}

    public Bill(String id, Double amount, OffsetDateTime createdAt, String ownerId, String type, String description) {
        this.id = id;
        this.amount = amount;
        this.createdAt = createdAt;
        this.ownerId = ownerId;
        this.type = type;
        this.description = description;
    }

    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    public Double getAmount() { return amount; }
    public void setAmount(Double amount) { this.amount = amount; }
    public OffsetDateTime getCreatedAt() { return createdAt; }
    public void setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; }
    public String getOwnerId() { return ownerId; }
    public void setOwnerId(String ownerId) { this.ownerId = ownerId; }
    public String getType() { return type; }
    public void setType(String type) { this.type = type; }
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Bill)) return false;
        Bill bill = (Bill) o;
        return Objects.equals(id, bill.id);
    }

    @Override
    public int hashCode() { return Objects.hash(id); }

    @Override
    public String toString() { return "Bill{" + "id='" + id + '\'' + ", amount=" + amount + '}'; }
}
